<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    
    <%@page import="support.*, java.util.*, java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Disciplines</title>
</head>
<body>

<%
	Class.forName("org.postgresql.Driver");

	Connection connect = DriverManager.getConnection("jdbc:postgresql://localhost/tester?user=postgres&password=admin");
	Statement stmt = connect.createStatement();
	Statement stmt2 = connect.createStatement();
	ResultSet discRset;
	ResultSet degreeRset;
	
	
	
	
	
	discRset = stmt.executeQuery("SELECT * FROM disciplines;");
	
	String discName = "";
	String discID = "";
	String discCount = "";
	%>
	<table border="1">
	<%
	while(discRset.next())
	{
		discName = discRset.getString("name");
		discID = discRset.getString("id");
		
		degreeRset = stmt2.executeQuery("SELECT count(*) FROM degrees WHERE discipline=" + discID );
		while( degreeRset.next() )
		{
			discCount = degreeRset.getString("count");
		}
		%>
		<tr>
		  <td><%=discName %></td>
		  <td width="50" align="right"><a href="Applications.jsp?discipline=<%=discName%>&disciplineID=<%= discID %>"> <%= discCount %> </a></td>
		</tr>
	<% } %>	

</table>

</body>
</html>